'use strict';

const BaseService = require('./base');
const modelName = 'Role';
class RouterService extends BaseService {
  constructor(ctx) {
    super(ctx, modelName);
  }

  async getPage(where, page, pageSize,include) {
    let list =  await this.ctx.model[this.modelName].findAndCountAll({
      where,
      offset: pageSize * (page - 1),
      limit: pageSize,
      order: [
        // id 降序
        ['id', 'DESC'],
      ],
      raw: true
    });
    let menuList = await this.ctx.model.Menu.findAll({
      raw: true
    })
    list.rows.forEach(item => {
        let menu = item.menu.split(',')
        let menuName = []
      console.log('menu',menu,menuList)
        menu.forEach(menuItem => {
          let find = menuList.find(menu => menu.id == menuItem)
          if (find) {
            menuName.push(find.name)
          }
        })
        item.menuName = menuName.join(',')
    })
    return list
  }
}


module.exports = RouterService;
